//
//  ByCellShopIndexFlexiblePart.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellShopIndexFlexiblePart.h"

@implementation ByCellShopIndexFlexiblePart

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setupUI {
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *lastView;
    for (int i = 0; i < _parts.count; i ++) {
        
        UIImageView *imageView = [UIImageView new];
        imageView.image = [UIImage imageNamed:@"头视图背景"];
        [self.contentView addSubview:imageView];
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.4];
        label.text = _parts[i];
        label.font = FONT(14);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor blackColor];
        [imageView addSubview:label];
        
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.right.equalTo(@-10);
            make.height.equalTo(imageView.mas_width).multipliedBy(11.0 / 35);
            if (i == 0) {
                make.top.equalTo(@10);
            } else {
                make.top.equalTo(lastView.mas_bottom).offset(10);
            }
        }];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(imageView);
            make.width.height.equalTo(imageView).multipliedBy(0.5);
        }];
        
        
        lastView = imageView;
    }
    
    
    [lastView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentView);
    }];
}

- (void)setParts:(NSArray *)parts {
    
    _parts = parts;
    
    [self setupUI];
}

@end
